package vip.xiaonuo.supplier.modular.purchase.suppliers.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.purchase.suppliers.entity.SupplierSuppliers;
import vip.xiaonuo.supplier.modular.purchase.suppliers.param.SupplierSuppliersAddParam;
import vip.xiaonuo.supplier.modular.purchase.suppliers.param.SupplierSuppliersEditParam;
import vip.xiaonuo.supplier.modular.purchase.suppliers.param.SupplierSuppliersIdParam;
import vip.xiaonuo.supplier.modular.purchase.suppliers.param.SupplierSuppliersPageParam;
import vip.xiaonuo.supplier.modular.purchase.suppliers.service.SupplierSuppliersService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 供应商控制器
 *
 * @author Mr.wu
 * @date  2025/02/28 21:58
 */
@Tag(name = "供应商控制器")
@RestController
@Validated
public class SupplierSuppliersController {

    @Resource
    private SupplierSuppliersService supplierSuppliersService;

    /**
     * 获取供应商分页
     *
     * @author Mr.wu
     * @date  2025/02/28 21:58
     */
    @Operation(summary = "获取供应商分页")
    @SaCheckPermission("/supplier/purchase/suppliers/page")
    @GetMapping("/supplier/purchase/suppliers/page")
    public CommonResult<Page<SupplierSuppliers>> page(SupplierSuppliersPageParam supplierSuppliersPageParam) {
        return CommonResult.data(supplierSuppliersService.page(supplierSuppliersPageParam));
    }

    /**
     * 添加供应商
     *
     * @author Mr.wu
     * @date  2025/02/28 21:58
     */
    @Operation(summary = "添加供应商")
    @CommonLog("添加供应商")
    @SaCheckPermission("/supplier/purchase/suppliers/add")
    @PostMapping("/supplier/purchase/suppliers/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierSuppliersAddParam supplierSuppliersAddParam) {
        supplierSuppliersService.add(supplierSuppliersAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑供应商
     *
     * @author Mr.wu
     * @date  2025/02/28 21:58
     */
    @Operation(summary = "编辑供应商")
    @CommonLog("编辑供应商")
    @SaCheckPermission("/supplier/purchase/suppliers/edit")
    @PostMapping("/supplier/purchase/suppliers/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierSuppliersEditParam supplierSuppliersEditParam) {
        supplierSuppliersService.edit(supplierSuppliersEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除供应商
     *
     * @author Mr.wu
     * @date  2025/02/28 21:58
     */
    @Operation(summary = "删除供应商")
    @CommonLog("删除供应商")
    @SaCheckPermission("/supplier/purchase/suppliers/delete")
    @PostMapping("/supplier/purchase/suppliers/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierSuppliersIdParam> supplierSuppliersIdParamList) {
        supplierSuppliersService.delete(supplierSuppliersIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取供应商详情
     *
     * @author Mr.wu
     * @date  2025/02/28 21:58
     */
    @Operation(summary = "获取供应商详情")
    @SaCheckPermission("/supplier/purchase/suppliers/detail")
    @GetMapping("/supplier/purchase/suppliers/detail")
    public CommonResult<SupplierSuppliers> detail(@Valid SupplierSuppliersIdParam supplierSuppliersIdParam) {
        return CommonResult.data(supplierSuppliersService.detail(supplierSuppliersIdParam));
    }
}
